package com.cgly.medical.util;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: medical
 * @description: 封装返回结果
 * @author: chen di
 * @create: 2022-08-15 16:16
 */
@Data
public class Msg {

    private Integer code;/*状态码*/

    private String message;/*响应信息*/

    private boolean success;/*响应是否成功的标志 */

    /*响应的数据*/
    private Map<String, Object> data = new HashMap<>();

    //成功
    public static Msg success(){
        Msg msg = new Msg();
        msg.setCode(20000);
        msg.setMessage("响应成功");
        msg.setSuccess(true);
        return msg;
    }

    //失败
    public static Msg fail(){
        Msg msg = new Msg();
        msg.setCode(10000);
        msg.setMessage("响应失败");
        msg.setSuccess(false);
        return msg;
    }

    //添加响应数据
    public Msg data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    //修改code
    public  Msg code(Integer code){
        this.setCode(code);
        return this;
    }

    //修改消息
    public  Msg mess(String str){
        this.setMessage(str);
        return this;
    }
}